#ifndef LASERCAMERAADAPTER_H
#define LASERCAMERAADAPTER_H
#include "GeneralDefine.h"

#include <QObject>
class ModbusMaster;
class QTimer;
class McControllerThread;

class LaserCameraAdapter : public QObject
{
    Q_OBJECT
public:
    explicit LaserCameraAdapter(QString configFileIn, int robotIdIn,McControllerThread *programMcControllerIn
                                ,QObject *parent = nullptr);

public:
    int setIsReadRegister(bool isRead);
    int getLaserCameraConfigParameter( struct LaserCameraConfigParameter &infoOut);
    int getLaserCameraStatus( struct LaserCameraStatusInfo &infoOut);
    int setLaserCameraConfigParameter( struct LaserCameraConfigParameter parameter);
    int reconnectLaserCamera();
    int setLaserCameraWork(bool isWork);
    int setLaserCameraShowLaser(bool isOn);
    int setLaserCameraJobId(int jobIdIn);

signals:
    void writeRegister_signal(int address,int value);//programengin线程发射
    void connectLaserCamera_signal();

public slots:
    void timeOut_slot();
    void readSucess_slot();
    void writeRegister_slot(int address,int value);//main线程响应
    void connectLaserCamera_slot();
private:
    void realTimeSleep(long long umicoroSecond);
    int writeConfigFile(QString configFileName,LaserCameraConfigParameter parameterIn);
    int initialConfigFile(QString configFileName);
    void addMsg(int messageLevel,
                 std::string componentName,
                 std::string messageType,
                 int messageCode,
                 int robotId,
                 int parameter1 = 0,
                 int parameter2 = 0,
                 int parameter3 = 0,
                 int parameter4 = 0 );
private:
    QString configFilePath;
    ModbusMaster *modbusMaster;
    QTimer* timer;
    bool isInitialOkStatus;
    LaserCameraConfigParameter cameraConfigParameter;
    bool isUseThisModule;
    int robotId;
    LaserCameraStatusInfo cameraStatus;
    McControllerThread *programMcController;
    bool isReadRegister;
};

#endif // LASERCAMERAADAPTER_H
